package com.geek.factory.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.geek.factory.entity.InventoryDistribution;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;

/**
 * <p>
 * 库存分布表 Mapper 接口
 * </p>
 *
 * @author author
 * @since 2025-06-27
 */
public interface InventoryDistributionMapper extends BaseMapper<InventoryDistribution> {
    /**
     * 获取产品的总库存
     * @param productId 产品ID
     * @return 总库存数量
     */
    @Select("SELECT COALESCE(SUM(quantity), 0) FROM inventory_distribution WHERE product_id = #{productId}")
    BigDecimal sumQuantityByProductId(@Param("productId") Integer productId);

    /**
     * 获取原料的总库存
     * @param materialId 原料ID
     * @return 总库存数量
     */
    @Select("SELECT COALESCE(SUM(quantity), 0) FROM inventory_distribution WHERE material_id = #{materialId}")
    BigDecimal sumQuantityByMaterialId(@Param("materialId") Integer materialId);
}
